package com.example.mcdonaldapplication.info

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.mcdonaldapplication.R

class GoodsTypeAdapter(private val typeList: ArrayList<GoodsInfo>) : RecyclerView.Adapter<GoodsTypeAdapter.ViewHolder>(){

    class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
        val tvGoodstype: TextView = itemView.findViewById(R.id.tvGoodstype)
        //val btnUse: android.widget.Button = itemView.findViewById(R.id.btnUse)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.goods_type_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = typeList[position]

        //餐品分类
        if(data.goodType == 0){
            holder.tvGoodstype.text="汉堡/卷"
        } else if(data.goodType == 1) {
            holder.tvGoodstype.text="炸鸡"
        } else if(data.goodType == 2) {
            holder.tvGoodstype.text="金拱门桶"
        } else if(data.goodType == 3) {
            holder.tvGoodstype.text="小食甜品"
        } else {
            holder.tvGoodstype.text="饮品"
        }


//        holder.tvTrashImage.setImageResource(data.image)

//        holder.btnUse.setOnClickListener{
//            val intent = Intent(context, OrderActivity::class.java)
//            context.startActivity(intent)
//        }

    }

    override fun getItemCount(): Int {
        return typeList.size
    }
}
